package zj.it.bhne.greendao;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import zj.it.bhne.greendao.entity.Students;

class Main2Adapter extends BaseAdapter {
    Context applicationContext;
    List<Students> teachersList;

    public Main2Adapter(Context applicationContext, List<Students> teachersList) {
        this.applicationContext = applicationContext;
        this.teachersList = teachersList;
    }

    @Override
    public int getCount() {
        return teachersList.size();
    }

    @Override
    public Object getItem(int position) {
        return teachersList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint({"SetTextI18n", "InflateParams"})
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder vieHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(applicationContext).inflate(R.layout.activity_main_list, null);
            vieHolder = new ViewHolder(convertView);
            convertView.setTag(vieHolder);
        } else
            vieHolder = (ViewHolder) convertView.getTag();
        Students teachers = teachersList.get(position);
        vieHolder.main_id.setText(teachers.getId()+"");
        vieHolder.main_name.setText(teachers.getName());
        vieHolder.main_age.setText(teachers.getAge()+"");

        return convertView;
    }


    public static class ViewHolder {
        public View rootView;
        public TextView main_id;
        public TextView main_name;
        public TextView main_age;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.main_id = (TextView) rootView.findViewById(R.id.main_id);
            this.main_name = (TextView) rootView.findViewById(R.id.main_name);
            this.main_age = (TextView) rootView.findViewById(R.id.main_age);
        }

    }
}
